package cn.yzh.service.impl;

import cn.yzh.dao.IStudentDao;
import cn.yzh.pojo.PageBean;
import cn.yzh.pojo.Student;
import cn.yzh.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 严志辉
 * 创建 2020/8/20 19:57
 * @version 1
 */
@Service
public class StudentServiceImpl implements IStudentService {

    @Autowired
    private IStudentDao studentdao;


    @Override
    public List<Student> findStudent(PageBean pageBean, String pg,Student stu) {
        pageBean.setRows(findStudentCount(stu));
        //设置当前页码
        int pgNum=0;
        //让初始页码不为0
        if(pg==null){
            pgNum=1;
        }else {
           pgNum=new Integer(pg);
        }

        if(pgNum<1){
            pgNum=1;
        }
        if(pgNum>pageBean.getPageCount()){
            pgNum=pageBean.getPageCount();
        }
        pageBean.setPage(pgNum);
        return studentdao.findStudent(pageBean);
    }

    @Override
    public int findStudentCount(Student stu) {
        return studentdao.findStudentCount(stu);
    }

    @Override
    public List<Student> findAll(Student student) {
        return studentdao.findAll(student);
    }
}
